#!/bin/bash
################################################################################
#       createidx.sh:	Create an index file containing information of the
#						filesystem.
#
#       Copyright 2008 Anish Mangal <anishmangal2002@gmail.com>
#
#       This program is free software; you can redistribute it and/or modify
#       it under the terms of the GNU General Public License as published by
#       the Free Software Foundation; either version 2 of the License, or
#       (at your option) any later version.
#
#       This program is distributed in the hope that it will be useful,
#       but WITHOUT ANY WARRANTY; without even the implied warranty of
#       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#       GNU General Public License for more details.
#
#       You should have received a copy of the GNU General Public License
#       along with this program; if not, write to the Free Software
#       Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
#       MA 02110-1301, USA.
################################################################################

USAGE="Usage: $0 [[-h][-n name] [-c] [-d directory]]"
compress=0
name=".default.idx"
directory="./"

while (( "$#" )); do
if [ "$1" == "-h" ]; then
        echo "$USAGE"
        exit 1
fi

if [ "$1" == "-c" ]; then
        compress=1
fi

if [ "$1" == "-n" ]; then
	name=$2
fi

if [ "$1" == "-d" ]; then
	directory=$2
fi
shift
done

echo "Indexing recursively from $directory"
echo "Creating and saving index in $name"

find $directory > $name

if [ "$compress" == "1" ]; then
	echo "Now compressing the index file"
	gzip $name
fi

exit 0
